package com.fc.redap.controller.api;

import com.alibaba.fastjson.JSONObject;
import com.fc.redap.controller.BaseController;
import com.fc.redap.dtos.ResponseJson;
import com.fc.redap.entity.ProjectScenicZoneEntity;
import com.fc.redap.entity.ScenicZoneEntity;
import com.fc.redap.service.IProjectScenicZoneService;
import com.fc.redap.service.IScenicZoneService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/project/scenic")
@Api(value="旅游景区地点相关的API", tags={"旅游项目景点"})
public class ProjectScenicZoneController extends BaseController {

    @Autowired
    private IProjectScenicZoneService projectScenicZoneService;

    @ApiOperation(value = "POST -- 获取项目关联的景区地点列表",
            notes = " REST 方式请求。"+
                    "Request Parameter: <ul>" +
                    "<li><i>必填参数: projectId: 项目ID</i></li>" +
                    "<li><i>可选参数: scenicId: 景点ID</i></li>" +
                    "<li><i>可选参数: count: 每页记录数, 默认10</i></li>" +
                    "<li><i>可选参数: page: 第几页, 从0开始</i></li>" +
                    "<li><i>可选参数: type: 0代表景点，1代表场馆</i></li>" +
                    "</ul>",
            response = ResponseJson.class,
            httpMethod = "POST",
            consumes = "application/json",
            produces = "application/json",
            code = 200
    )
    @PostMapping("/list")
    public ResponseJson doQueryList(@RequestBody JSONObject params) {

        params.put("limit",params.get("count"));
        params.put("offset",params.get("page"));
        //校对并赋值 offset和limit
        calculatePagination(params);

        List<ProjectScenicZoneEntity> projectList = projectScenicZoneService.queryList(params);
        return ResponseJson.success(projectList);
    }

    @ApiOperation(value = "POST -- 保存项目与景区地点的关联信息",
            notes = " REST 方式请求" +
                    "Request Body: <ul>" +
                    "<li><i>必填参数：projectId: 项目id</i></li>" +
                    "<li><i>必填参数：scenicId: 景区地点ID</i></li>" +
                    "<li><i>必填参数：scenicZoneName: 景区名称</i></li>" +
                    "<li><i>可选参数：order: 排序</i></li>" +
                    "<li><i>可选参数：startTime: 停留开始时间 格式：yyyy-MM-dd HH:mm:SS 例如 2018-06-19 07:54:01</i></li>" +
                    "<li><i>可选参数：endTime: 停留结束时间 格式：yyyy-MM-dd HH:mm:SS 例如 2018-06-19 07:54:01</i></li>" +
                    "<li><i>可选参数：remark: 备注</i></li>" +
                    "</ul>",
            response = ResponseJson.class,
            httpMethod = "POST",
            consumes = "application/json",
            produces = "application/json",
            code = 200
    )
    @PostMapping("/save")
    public ResponseJson doSave(@RequestBody ProjectScenicZoneEntity pScenicZoneEntity) {
        projectScenicZoneService.save(pScenicZoneEntity);
        return ResponseJson.success();
    }

    @ApiOperation(value = "PUT -- 更新项目与景区地点的关联信息",
            notes = " REST 方式请求" +
                    "Request Body: <ul>" +
                    "<li><i>必填参数：projectId: 项目id</i></li>" +
                    "<li><i>必填参数：scenicId: 景区地点ID</i></li>" +
                    "<li><i>必填参数：scenicZoneName: 景区名称</i></li>" +
                    "<li><i>可选参数：order: 排序</i></li>" +
                    "<li><i>可选参数：startTime: 停留开始时间 格式：yyyy-MM-dd HH:mm:SS 例如 2018-06-19 07:54:01</i></li>" +
                    "<li><i>可选参数：endTime: 停留结束时间 格式：yyyy-MM-dd HH:mm:SS 例如 2018-06-19 07:54:01</i></li>" +
                    "<li><i>可选参数：remark: 备注</i></li>" +
                    "</ul>",
            response = ResponseJson.class,
            httpMethod = "PUT",
            consumes = "application/json",
            produces = "application/json",
            code = 200
    )
    @PutMapping("/update")
    public ResponseJson doUpdate(@RequestBody ProjectScenicZoneEntity pScenicZoneEntity) {
        projectScenicZoneService.update(pScenicZoneEntity);
        return ResponseJson.success();
    }

    @ApiOperation(value = "POST -- 批量删除项目与景区地点的关联信息",
            notes = " REST 方式请求" +
                    "Request Body: <ul>" +
                    "<li><i>必填参数：ids: 项目景区地点关联信息id 数组</i></li>" +
                    "</ul>")
    @PostMapping("/delete")
    public ResponseJson doDelete(@RequestBody Long[] ids) {
        projectScenicZoneService.deleteBatch(ids);
        return ResponseJson.success();
    }

    @ApiOperation(value = "POST -- 根据项目ID删除所有项目与景区地点的关联信息",
            notes = " REST 方式请求" +
                    "Request Body: <ul>" +
                    "<li><i>必填参数：projectId: 项目ID</i></li>" +
                    "</ul>")
    @PostMapping("/deletesByProjectId")
    public ResponseJson doDeleteByProjectId(@RequestBody Long projectId) {
        projectScenicZoneService.deleteByProjectId(projectId);
        return ResponseJson.success();
    }
}
